#include<iostream>
#include<string>
using namespace std;
const int N = 3e3 + 10;
int a[N], b[N];
int n;
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (int i = 1; i <= n; i++) {
		cin >> b[i];
	}
	//i<j && j<k
	/*for (int i = 1; i <= n; i++) {
		for (int j = i + 1; j <= n; j++) {
			for (int k = j + 1; k <= n; k++) {
				             
			}
		}
	}*/
	int ans = 1e9;
	for (int i = 2; i <= n - 1; i++) {
		int mi1 = 1e9;
		int mi2 = 1e9;
		for (int j = 1; j <= i - 1; j++) {
			if (a[i] > a[j]) {
				mi1 = min(mi1, b[j]);
			}
		}
		for (int j = i + 1; j <= n; j++) {
			if (a[i] < a[j]) {
				mi2 = min(mi2, b[j]);
			}
		}
		/*cout << "mi1==" << mi1 << endl;
		cout << "mi2==" << mi2 << endl;*/
		ans = min(ans, mi1 + mi2 + b[i]);
	}
	if (ans == 1e9) {
		cout << -1 << endl;
	}
	else cout << ans << endl;
	return 0;
}